package com.cqemme.hardwareservice.schedule;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cqemme.comm.constraint.MqNames;
import com.cqemme.comm.enums.AlarmType;
import com.cqemme.comm.po.Result;
import com.cqemme.comm.utils.DateUtils;
import com.cqemme.comm.utils.JackSonUtils;
import com.cqemme.hardwareservice.feign.SchoolServiceFeign;
import com.cqemme.hardwareservice.po.AccessRecordPo;
import com.cqemme.hardwareservice.po.EarlyWarningPo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @author 86156
 * // 2.开启定时任务
 * //1.主要用于标记配置类，兼备Component的效果。
 */
@Component
@Configuration
@EnableScheduling
@Slf4j
public class SaticScheduleTask {


    @Autowired
    private SchoolServiceFeign schoolServiceFeign;
    @Autowired
    private AmqpTemplate amqpTemplate;

//    /**火灾报警器**/
//    @Scheduled(cron = "0 */30 * * * ?")
//    public void executeSettle() {
//        log.info("执行了操作1！"+System.currentTimeMillis());
//        Result result = schoolServiceFeign.queryAllByDevice(55);
//        String jr = result.getData().toString();
//        log.info(jr);
//        JSONArray jrr = JSONObject.parseArray(jr);
//        System.out.println(jrr.size());
//        List<Map<String,Object>> map = new ArrayList<>();
//        for (int i = 0; i < jrr.size(); i++) {
//            Map<String,Object> cmap = new HashMap<>();
//            cmap.put("type", AlarmType.FIRE.getKey());
//            JSONObject jo = jrr.getJSONObject(i);
//            Map<String,Object> mapc2 = new HashMap<>();
//            mapc2.put("deviceNumber",jo.getString("deviceNumber"));
//            cmap.put("data",mapc2);
//            log.info(JackSonUtils.beanToString(cmap));
//            map.add(cmap);
//        }
//        for (Map<String,Object> data: map
//             ) {
//            amqpTemplate.convertAndSend(MqNames.SCHOOL_HARDWARE_TO_ACTIVITI_ALARM,JackSonUtils.beanToString(data));
//        }
//
//
//
//    }
//    /**报警住**/
//    @Scheduled(cron = "0 */15 * * * ?")
//    public void executeSettle2() {
//        log.info("执行了操作2！"+System.currentTimeMillis());
//        Result result = schoolServiceFeign.queryAllByDevice(34);
//        String jr = result.getData().toString();
//        log.info(jr);
//        JSONArray jrr = JSONObject.parseArray(jr);
//        System.out.println(jrr.size());
//        List<Map<String,Object>> map = new ArrayList<>();
//        for (int i = 0; i < jrr.size(); i++) {
//            Map<String,Object> cmap = new HashMap<>();
//            cmap.put("type", AlarmType.ALARM_PILLAR.getKey());
//            JSONObject jo = jrr.getJSONObject(i);
//            Map<String,Object> mapc2 = new HashMap<>();
//            mapc2.put("deviceNumber",jo.getString("deviceNumber"));
//            cmap.put("data",mapc2);
//            log.info(JackSonUtils.beanToString(cmap));
//            map.add(cmap);
//        }
//        for (Map<String,Object> data: map
//        ) {
//            amqpTemplate.convertAndSend(MqNames.SCHOOL_HARDWARE_TO_ACTIVITI_ALARM,JackSonUtils.beanToString(data));
//        }
//    }
//    /**系统识别黑名单--人脸识别门禁**/
//    @Scheduled(cron = "0 */16 * * * ?")
//    public void executeSettle3() {
//        log.info("执行了操作3！"+System.currentTimeMillis());
//        Result result = schoolServiceFeign.queryAllByDevice(4);
//        String jr = result.getData().toString();
//        log.info(jr);
//        JSONArray jrr = JSONObject.parseArray(jr);
//        System.out.println(jrr.size());
//        List<Map<String,Object>> map = new ArrayList<>();
//        for (int i = 0; i < jrr.size(); i++) {
//            Map<String,Object> cmap = new HashMap<>();
//            cmap.put("type", AlarmType.BLACKLIST.getKey());
//            JSONObject jo = jrr.getJSONObject(i);
//            Map<String,Object> mapc2 = new HashMap<>();
//            mapc2.put("deviceNumber",jo.getString("deviceNumber"));
//            EarlyWarningPo er = new EarlyWarningPo();
//            er.setOrgCode(jo.getInteger("siOrgCode").toString());
//            er.setComparisonImage("https://b-ssl.duitang.com/uploads/item/201509/30/20150930140213_ZCFSr.jpeg");
//            er.setDeviceId(jo.getInteger("deviceId").toString());
//            er.setTenantId(jo.getInteger("tenantId").toString());
//            er.setSnapImage("https://b-ssl.duitang.com/uploads/item/201509/30/20150930140213_ZCFSr.jpeg");
//            er.setEarlyDevice(jo.getString("name"));
//            er.setEarlyTime(DateUtils.standardFmtsS(new Date()));
//            mapc2.put("info",er);
//            cmap.put("data",mapc2);
//            log.info(JackSonUtils.beanToString(cmap));
//            map.add(cmap);
//        }
//        for (Map<String,Object> data: map
//        ) {
//            amqpTemplate.convertAndSend(MqNames.SCHOOL_HARDWARE_TO_ACTIVITI_ALARM,JSONObject.toJSONString(data));
//        }
//    }
//
//    /**非校内人员徘徊识别--人脸识别门禁**/
//    @Scheduled(cron = "0 */16 * * * ?")
//    public void executeSettle4() {
//        log.info("执行了操作4！"+System.currentTimeMillis());
//        Result result = schoolServiceFeign.queryAllByDevice(4);
//        String jr = result.getData().toString();
//        log.info(jr);
//        JSONArray jrr = JSONObject.parseArray(jr);
//        System.out.println(jrr.size());
//        List<Map<String,Object>> map = new ArrayList<>();
//        for (int i = 0; i < jrr.size(); i++) {
//            if(i==0){
//
//            }
//            Map<String,Object> cmap = new HashMap<>();
//            cmap.put("type", AlarmType.IRRELEVANT_PERSONNEL_WANDERING.getKey());
//            JSONObject jo = jrr.getJSONObject(i);
//            Map<String,Object> mapc2 = new HashMap<>();
//            mapc2.put("deviceNumber",jo.getString("deviceNumber"));
//            EarlyWarningPo er = new EarlyWarningPo();
//            er.setOrgCode(jo.getInteger("siOrgCode").toString());
//            er.setComparisonImage("https://b-ssl.duitang.com/uploads/item/201509/30/20150930140213_ZCFSr.jpeg");
//            er.setDeviceId(jo.getInteger("deviceId").toString());
//            er.setTenantId(jo.getInteger("tenantId").toString());
//            er.setSnapImage("https://b-ssl.duitang.com/uploads/item/201509/30/20150930140213_ZCFSr.jpeg");
//            er.setEarlyDevice(jo.getString("name"));
//            er.setEarlyTime(DateUtils.standardFmtsS(new Date()));
//            mapc2.put("info",er);
//            cmap.put("data",mapc2);
//            log.info(JackSonUtils.beanToString(cmap));
//            map.add(cmap);
//        }
//        for (Map<String,Object> data: map
//        ) {
//            amqpTemplate.convertAndSend(MqNames.SCHOOL_HARDWARE_TO_ACTIVITI_ALARM,JSONObject.toJSONString(data));
//        }
//    }
//
//    /**非法进出门禁--人脸识别门禁**/
//    @Scheduled(cron = "0 */16 * * * ?")
//    public void executeSettle5() {
//        log.info("执行了操作5！"+System.currentTimeMillis());
//        Result result = schoolServiceFeign.queryAllByDevice(4);
//        String jr = result.getData().toString();
//        log.info(jr);
//        JSONArray jrr = JSONObject.parseArray(jr);
//        System.out.println(jrr.size());
//        List<Map<String,Object>> map = new ArrayList<>();
//        for (int i = 0; i < jrr.size(); i++) {
//            if(i==0){
//                Map<String,Object> cmap = new HashMap<>();
//                cmap.put("type", AlarmType.MJ_ILLEGAL_ACCESS.getKey());
//                JSONObject jo = jrr.getJSONObject(i);
//                Map<String,Object> mapc2 = new HashMap<>();
//                mapc2.put("deviceNumber",jo.getString("deviceNumber"));
//                AccessRecordPo arp = new AccessRecordPo();
//                arp.setUnusual(true);
//                arp.setImage("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1583213643123&di=f919962d87f00854a52f1dc5b5656bf3&imgtype=0&src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fq_70%2Cc_zoom%2Cw_640%2Fimages%2F20180916%2F6ad375579e5640858e6c09bfa0bea936.jpeg");
//                arp.setOrgCode(jo.getInteger("siOrgCode").toString());
//                arp.setCreateTime(DateUtils.standardFmtsS(new Date()));
//                arp.setFaceGroupName("测试类型");
//                arp.setDeviceId(jo.getInteger("deviceId").toString());
//                arp.setTenantId(jo.getInteger("tenantId").toString());
//                arp.setIdCardNo("532101201569569856");
//                arp.setUserType("定时任务发送-学生");
//                arp.setFaceGroupName("定时产生数据");
//                arp.setUserId("532101201569569856");
//                arp.setUserCardNo("532101201569569856");
//                arp.setGrade("测试-定时任务发送");
//                arp.setThroughType("刷脸");
//                mapc2.put("info",arp);
//                cmap.put("data",mapc2);
//                log.info(JSONObject.toJSONString(cmap));
//                map.add(cmap);
//            }
//
//        }
//        for (Map<String,Object> data: map
//        ) {
//            amqpTemplate.convertAndSend(MqNames.SCHOOL_HARDWARE_TO_ACTIVITI_ALARM,JackSonUtils.beanToString(data));
//        }
//    }
//
//    /**电子围栏非法入侵---防区设备识别**/
//    @Scheduled(cron = "0 */16 * * * ?")
//    public void executeSettle6() {
//        log.info("执行了操作6！"+System.currentTimeMillis());
//        Result result = schoolServiceFeign.queryAllByDevice(56);
//        String jr = result.getData().toString();
//        log.info(jr);
//        JSONArray jrr = JSONObject.parseArray(jr);
//        System.out.println(jrr.size());
//        List<Map<String,Object>> map = new ArrayList<>();
//        for (int i = 0; i < jrr.size(); i++) {
//            Map<String,Object> cmap = new HashMap<>();
//            cmap.put("type", AlarmType.PRECAUTIONARY_AREA.getKey());
//            JSONObject jo = jrr.getJSONObject(i);
//            Map<String,Object> mapc2 = new HashMap<>();
//            mapc2.put("deviceNumber",jo.getString("deviceNumber"));
//            cmap.put("data",mapc2);
//            log.info(JackSonUtils.beanToString(cmap));
//            map.add(cmap);
//        }
//        for (Map<String,Object> data: map
//        ) {
//            amqpTemplate.convertAndSend(MqNames.SCHOOL_HARDWARE_TO_ACTIVITI_ALARM,JackSonUtils.beanToString(data));
//        }
//    }


}
